#pragma once
#include "inc.h"
class GScene;
class Payload;
class GModel;
class VertexProp;

typedef enum
{
	W_PLANE,
	X_RIGHT,
	X_LEFT,
	Y_TOP,
	Y_BOTTOM,
	Z_NEAR,
	Z_FAR
} clip_plane;

class GRender
{
public:
	GRender();
	void Render(GScene* pScene, Payload& payload);
	void SetRenderTarget(GRenderTarget* pRenderTarget);
	void DrawPixel(int nX, int nY, unsigned int color);
	void ClearRenderTarget();
private:
	Vector3f CalcBarycentric2D(float x, float y, Vector4f* v);
	void LerpVertexProp(VertexProp* vp1, VertexProp* vp2, VertexProp* vpDst, float fRatio);
	bool IsInsideTriangle(int nPosX, int nPosY, const Vector4f* pVert);
	bool IsInsidePlane(clip_plane plane, Vector4f vertex);
	float CalcIntersectRatio(clip_plane plane, Vector4f prev, Vector4f curv);
	int ClipWithPlane(clip_plane plane, Payload& payload, int nVertNums);
	void RasterizeTriangle(Payload& payload);
	inline int Homo_Clipping(Payload& payload);
	inline void DrawModel(GModel* pModel, Payload& payload);
	inline void FillRenderTarget(int nOffset, void* pData, unsigned char uSize);
	inline int GetScreenPosIndex(int nX, int nY);
	GRenderTarget* m_pRenderTarget;
};